package junyi.power.actions;

import junyi.card.Card;
import junyi.card.CardFilter;
import junyi.player.Player;
import junyi.power.Action;
import junyi.power.effects.DropObject;
import junyi.power.effects.Effect;
import junyi.power.effects.EffectSource;
import junyi.power.effects.PickObject;

import java.util.ArrayList;
import java.util.List;

/**
 * User: Junyi BEI
 * Date: 12-9-30
 * Time: 下午4:26
 */
public class TargetPlayerDropSelectedCard extends Action {
  
  private Player target;
  private List<Card> cards;
  private CardFilter cardFilter;
  private int number;
  private int acceptable;


  // target -> source -> card_filter
  public TargetPlayerDropSelectedCard(Player t, List<Card> cs, CardFilter cf, int n, int a,  EffectSource es) {
    super(es);
    target = t;
    cards = cs;
    cardFilter = cf;
    number = n;
    acceptable = a;
  }


  @Override
  public int start(int c) {
    List<Card> hand = target.getHand();
    List<Card> selection = new ArrayList<Card>();
    Effect pickEffect = new PickObject(target, cardFilter.doFilter(cards), number, selection, effectSource);
    int result =  pickEffect.start();
    if(selection.isEmpty() || !toContinue(result, acceptable)) {
      return result;
    }
    Effect dropObject = new DropObject(target, selection, effectSource);
    return dropObject.start();
  }

  public Player getTarget() {
    return target;
  }

  public void setTarget(Player target) {
    this.target = target;
  }

  public List<Card> getCards() {
    return cards;
  }

  public void setCards(List<Card> cards) {
    this.cards = cards;
  }

  public CardFilter getCardFilter() {
    return cardFilter;
  }

  public void setCardFilter(CardFilter cardFilter) {
    this.cardFilter = cardFilter;
  }
}
